/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.uta.tsrh.specialnotes.misc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.mysql.jdbc.Driver;

/**
 *
 * @author David
 */
public class SQLConnMgr {
    private static Connection connection = null;

    /* This is a terrible, wretched thing to do, but I'm going to do it anyway for now */
    private static final String url = "jdbc:mysql://localhost:3306/ews";
    private static final String user = "root";
    private static final String password = "1234";
    
    public static Connection getConnection() {
        openDB();
        return connection;
    }
    
    private static void openDB() {
        if (SQLConnMgr.connection == null) {
            try {
                try {
                    Class.forName("com.mysql.jdbc.Driver");
                } catch (ClassNotFoundException ex) {
                    Logger.getLogger(SQLConnMgr.class.getName()).log(Level.SEVERE, null, ex);
                }
                SQLConnMgr.connection = DriverManager.getConnection(url, user, password);
            } catch (SQLException ex) {
                System.out.println("Cannot connection to database!");
                Logger.getLogger(SQLMgr.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
}
